package com.coda.mapper;

import com.coda.adminVo.agreement.AgreementQueryVo;
import com.coda.adminVo.agreement.AgreementVo;
import com.coda.annotation.AutoFill;
import com.coda.entity.LeaseAgreement;
import com.coda.enumeration.OperationType;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface LeaseAgreementMapper {
    /**
     * 分页查询
     * @param queryVo
     * @return
     */
    Page<AgreementVo> getPageList(AgreementQueryVo queryVo);
    /**
     * 根据id查询租约信息
     * @param id
     * @return
     */
    @Select("select * from lease_agreement where id = #{id}")
    LeaseAgreement getViewAppointement(Long id);

    /**
     * 插入租约信息
     * @param leaseAgreement
     */
    @AutoFill(OperationType.INSERT)
    void insert(LeaseAgreement leaseAgreement);

    /**
     * 更新租约信息
     * @param leaseAgreement
     */
    @AutoFill(OperationType.UPDATE)
    void update(LeaseAgreement leaseAgreement);

    /**
     * 根据ID删除租约信息
     * @param id
     */
    @Delete("delete from lease_agreement where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据ID更新租约状态
     * @param
     */
    @AutoFill(OperationType.UPDATE)
    @Update("update lease_agreement set status = #{status} where id = #{id}")
    void updateStatus(LeaseAgreement leaseAgreement);

    @Select("select count(*) from lease_agreement where apartment_id = #{apartmentId} and room_id = #{roomId} and status in (1,2,5,7)")
    int getCount(LeaseAgreement leaseAgreement);
}
